define(["require", "exports", "vscode-html-languageservice", "../languageModelCache", "./embeddedSupport", "./cssMode", "./javascriptMode", "./htmlMode", "vscode-languageserver-protocol"], function (require, exports, vscode_html_languageservice_1, languageModelCache_1, embeddedSupport_1, cssMode_1, javascriptMode_1, htmlMode_1, vscode_languageserver_protocol_1) {
    /*---------------------------------------------------------------------------------------------
     *  Copyright (c) Microsoft Corporation. All rights reserved.
     *  Licensed under the MIT License. See License.txt in the project root for license information.
     *--------------------------------------------------------------------------------------------*/
    'use strict';
    function __export(m) {
        for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
    }
    Object.defineProperty(exports, "__esModule", { value: true });
    __export(vscode_languageserver_protocol_1);
    function getLanguageModes(supportedLanguages) {
        var htmlLanguageService = vscode_html_languageservice_1.getLanguageService();
        let documentRegions = languageModelCache_1.getLanguageModelCache(10, 60, document => embeddedSupport_1.getDocumentRegions(htmlLanguageService, document));
        let modelCaches = [];
        modelCaches.push(documentRegions);
        let modes = Object.create(null);
        modes['html'] = htmlMode_1.getHTMLMode(htmlLanguageService);
        if (supportedLanguages['css']) {
            modes['css'] = cssMode_1.getCSSMode(documentRegions);
        }
        if (supportedLanguages['javascript']) {
            modes['javascript'] = javascriptMode_1.getJavascriptMode(documentRegions);
        }
        return {
            getModeAtPosition(document, position) {
                let languageId = documentRegions.get(document).getLanguageAtPosition(position);
                if (languageId) {
                    return modes[languageId];
                }
                return void 0;
            },
            getModesInRange(document, range) {
                return documentRegions.get(document).getLanguageRanges(range).map(r => {
                    return {
                        start: r.start,
                        end: r.end,
                        mode: r.languageId && modes[r.languageId],
                        attributeValue: r.attributeValue
                    };
                });
            },
            getAllModesInDocument(document) {
                let result = [];
                for (let languageId of documentRegions.get(document).getLanguagesInDocument()) {
                    let mode = modes[languageId];
                    if (mode) {
                        result.push(mode);
                    }
                }
                return result;
            },
            getAllModes() {
                let result = [];
                for (let languageId in modes) {
                    let mode = modes[languageId];
                    if (mode) {
                        result.push(mode);
                    }
                }
                return result;
            },
            getMode(languageId) {
                return modes[languageId];
            },
            onDocumentRemoved(document) {
                modelCaches.forEach(mc => mc.onDocumentRemoved(document));
                for (let mode in modes) {
                    modes[mode].onDocumentRemoved(document);
                }
            },
            dispose() {
                modelCaches.forEach(mc => mc.dispose());
                modelCaches = [];
                for (let mode in modes) {
                    modes[mode].dispose();
                }
                modes = {};
            }
        };
    }
    exports.getLanguageModes = getLanguageModes;
});
